package com.xiangxiao.rpan.authority.serializer;

import com.xiangxiao.rpan.utils.DateUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.sql.Date;
import java.util.Objects;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2022/12/29 15:08
 */
public class Date2StringSerializer extends JsonSerializer<Date> {
  @Override
  public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    if (Objects.isNull(date)) {
      jsonGenerator.writeString(StringUtils.EMPTY);
    } else {
      jsonGenerator.writeString(DateUtil.stdDate2String(date));
    }
  }
}
